<?php
class ZAction extends spController {
	
	public function __construct(){
		parent::__construct();
		$this->c_default();
	}
	
	function index(){
		$this->is_index = 1;
	}
	
	public function change_entrance(){
		$id = $this->spArgs("id");
		$_SESSION["sys_entrance"] = spClass("entrance")->getByMark($id);
		echo json_encode(array("reload"=>1, "result"=>1));
		exit();
	}
	
	function search(){
		$postdata = $this->spArgs();
		$products = spClass('article');
		$obj_filter = spClass("articlefilter");
		$obj_extval = spClass("article_extval");
		$keys = trim(urldecode($postdata['keys']));
		if ($keys == "请输入您要搜索的内容" || !$keys){
			$this->redirect(spUrl("main", "index"), "请输入您要搜索的内容");
		}
		$page = intval(max($postdata['page'], 1));
		if ($list_rs = $products->join("hnyn_articlestyle", "hnyn_articlestyle.sid = hnyn_articles.ptype and hnyn_articlestyle.islist = 1")->spPager($page, 1)->findAll("hnyn_articles.name like '%$keys%'", "hnyn_articles.`hits` desc, hnyn_articles.`posttime` desc, hnyn_articles.`pid` desc", "hnyn_articles.*")) {
			foreach ($list_rs as $key => $val){
				if ($val['picurlfile']) $list_rs[$key]['thumb'] = $val['picurlfile'] ? $val['picurlpath']."thumb_".$val['picurlfile'] : "";
				if ($val['picurlfile']) $list_rs[$key]['pic'] = $val['picurlfile'] ? $val['picurlpath'].$val['picurlfile'] : "";
				if ($val['posttime']) $list_rs[$key]["ftime"] = date("Y-m-d", strtotime($val['posttime']));
				$list_rs[$key]['turl'] = spUrl("main", "cdetail", array("id"=>$val['pid']));
				$list_rs[$key]["extfield"] = $obj_extval->extval_get_mark($val["pid"]);
				if($val["filter2_id"]){
					if($filter_rs = $obj_filter->findAll("pc_id in({$val["filter2_id"]}) and fid <> 0", null, "pc_id, fid, pc_name")){
						foreach($filter_rs as $k => $v){
							$list_rs[$key]["thisfilter"][$v["fid"]][] = array("pc_id"=>$v["pc_id"], "pc_name"=>$v["pc_name"]);
						}
					}
				}
			}
		}
		/*
		$this->main_column_rs = array("sid"=>1, "sname"=>"产品中心");
		$this->column_rs = array("sid"=>7, "sname"=>"产品中心");
		*/
		$this->list_rs = $list_rs;
		$this->pager = $products->spPager()->getPager();
		$this->c = "main";
		$this->a = "search";
		$this->keys = $keys;
	}
	
	function runclick(){
		$id = intval($this->spArgs("id"));
		$w = intval($this->spArgs("w"));
		if(!$id){
			echo "document.write('0')";
			exit();
		}
		$products = spClass("article");
		if($rs = $products->find(array("pid"=>$id), null, "hits")){
			$info = intval($rs['hits']) + 1;
			$products->update(array("pid"=>$id), array("hits"=>$info));
		}else{
			$info = 1;
		}
		if($w) echo "document.write('$info')";
		exit();
	}
	
	function getclick(){
		$id = intval($this->spArgs("id"));
		if(!$id){
			echo "document.write('0')";
			exit();
		}
		$products = spClass("article");
		$info = ($rs = $products->find(array("pid"=>$id), null, "hits")) ? $rs['hits'] : "0";
		echo "document.write('$info')";
		exit();
	}
	
	//所属栏目_新闻
	function getsubcolumn(){
		$id = intval($this->spArgs("id"));
		$sub = intval($this->spArgs("sub"));
		$link = intval($this->spArgs("link"));
		if(!$id){
			echo "document.write('-')";
			exit();
		}
		$products = spClass("article");
		$info = ($rs = $products->join("hnyn_articles as a", "a.pid = hnyn_articles.subproduct")->find(array("hnyn_articles.pid"=>$id), null, "a.name, hnyn_articles.pid, hnyn_articles.subproduct")) ? $rs['name'] : "-";
		if($sub) $info = $this->removehtml($info, $sub);
		if($link && $rs) $info = "<a href=\'".spUrl("main", "cdetail", array("id"=>$rs['subproduct']))."\'>".$info."</a>";
		echo "document.write('$info')";
		exit();
	}
	
	//所属栏目_栏目
	function getsubcolumn_c(){
		$id = intval($this->spArgs("id"));
		$sub = intval($this->spArgs("sub"));
		$link = intval($this->spArgs("link"));
		if(!$id){
			echo "document.write('-')";
			exit();
		}
		$products = spClass("article");
		$info = ($rs = $products->join("hnyn_articlestyle as a", "a.sid = hnyn_articles.subproduct")->find(array("hnyn_articles.pid"=>$id), null, "a.sname, a.sid")) ? $rs['sname'] : "-";
		if($sub) $info = $this->removehtml($info, $sub);
		if($link && $rs) $info = "<a href=\'".spUrl("main", "cdetail", array("id"=>$rs['subproduct']))."\'>".$info."</a>";
		echo "document.write('$info')";
		exit();
	}
	
	//关联栏目_新闻
	function getlinkstr(){
		$id = intval($this->spArgs("id"));
		$cid = intval($this->spArgs("cid"));
		$link = intval($this->spArgs("link"));
		if(!$id){
			echo "document.write('-')";
			exit();
		}
		$products = spClass("article");
		$p_rs = $products->findByPk($id, "relatestr");
		$condition = "pid in ($p_rs[relatestr])";
		if($cid) $condition .= " and ptype = $cid";
		if(!$rs = $products->findAll($condition, null, "hnyn_articles.name, hnyn_articles.pid")){
			echo "document.write('-')";
			exit();
		}
		foreach ($rs as $key => $val){
			if($key > 0) $info .= ", ";
			$info .= $link ? "<a href=\'".spUrl("main", "cdetail", array("id"=>$val['pid']))."\'>".$val['name']."</a>" : $val['name'];
		}
		echo "document.write('$info')";
		exit();
	}
	
	//上一篇,下一篇
	function getprepnext(){
		$id = intval($this->spArgs("id"));
		$cid = intval($this->spArgs("cid"));
		$fpid = intval($this->spArgs("fpid"));
		$sub = intval($this->spArgs("sub"));
		$act = $this->spArgs("act");
		if(!$id || !$cid || !in_array($act, array("prep", "next"))){
			echo "document.write('没有了')";
			exit();
		}
		$sort = "hnyn_articles.`top` desc, hnyn_articles.`recomd` desc, hnyn_articles.stj_hot desc, hnyn_articles.stj_news desc, hnyn_articles.stj_soldout asc, hnyn_articles.`specrecomd` desc, hnyn_articles.`order` asc, hnyn_articles.`status` desc, hnyn_articles.`posttime` desc, hnyn_articles.`pid` desc";
		$products = spClass("article");
		if($fpid){
			if(!$rs = $products->join("hnyn_articlescato")->findAll(array("hnyn_articles.ptype"=>$cid, "hnyn_articlescato.fid"=>$fpid), $sort, "hnyn_articles.name, hnyn_articles.pid")){
				echo "document.write('没有了')";
				exit();
			}
		}else{
			if(!$rs = $products->findAll(array("ptype"=>$cid), $sort, "hnyn_articles.name, hnyn_articles.pid")){
				echo "document.write('没有了')";
				exit();
			}
		}

		$offset = 0;
		$lastkey = 0;
		foreach ($rs as $key=>$val){
			if($val['pid'] == $id) $offset = $key;
			$lastkey = $key;
		}
		try {
			switch ($act){
				case "prep":
					if($offset == 0) throw new Exception("none");
					$getdata = $rs[($offset-1)];
				break;
				case "next":
					if($offset == $lastkey) throw new Exception("none");
					$getdata = $rs[($offset+1)];
				break;
			}
		}catch (Exception $e){
			echo "document.write('没有了')";
			exit();
		}
		/*
		print_r($rs);
		echo $offset;
		echo $lastkey;
		print_r($getdata);
		exit();
		*/
		if($sub) $getdata['name'] = $this->removeHtml($getdata['name'], $sub);
		echo "document.write('<a href=\'".spUrl("main", "cdetail", array("id"=>$getdata['pid']))."\'>".$getdata['name']."</a>')";
		exit();
	}
	
	function message(){
		$this->c_defaultlist();
		$liuyan = spClass('liuyan');
		if($this->spArgs("tip")){
			$this->tip = urldecode($this->spArgs("tip"))."\r";
		}
		$this->parenttitle = "联系我们";
		$this->validator = $liuyan->getValidatorJS();
		$this->headertitle = "在线留言-";
		$this->saveurl = spUrl("main", "messagesave");
	}
	
	function messagesave(){
		if($_SERVER['REQUEST_METHOD'] == 'POST'){
			try {
				$liuyan = spClass('liuyan');
				import("Common.php");
				$postdata = $this->spArgs();
				$data = array();
				//客户端提交方法
				$data['name'] = $postdata['name'];
				$data['telephone'] = $postdata['telephone'];
				$data['question'] = $postdata['msg_prep'] != $postdata['question'] ? $postdata['msg_prep'] . $postdata['question'] : $postdata['question'];
				$data['ipaddress'] = Common::GetIP();
				$data['createtime'] = time();
				/*
				$data['verify'] = $postdata['verify'];
				if(!$data['verify'])
					throw new Exception("请输入验证码");
				if (strtolower($data['verify']) !== strtolower($_SESSION['captcha']))
					throw new Exception('验证码不正确,请重新输入！');
				*/
				if($result = $liuyan->spValidator($data)) {
					foreach($result as $item)
						throw new Exception($item[0]);
				}
				/*
				if(!preg_match('/^[A-Za-z0-9]+([._\-\+]*[A-Za-z0-9]+)*@([A-Za-z0-9-]+\.)+[A-Za-z0-9]+$/', $data['email']))
					throw new Exception("请输入正确的邮箱格式");
				*/
				if(!preg_match('/(^([0-9]{3}-)?(2|8)[0-9]{7}$|^(13[0-9]|15[0-9]|18[0-9])[0-9]{8}$)/',$data['telephone']))
					throw new Exception("请输入11位正确的手机号码");
				unset($data['verify']);
				if(!$liuyan->create($data))
					throw new Exception('留言提交失败,请稍后再试！');
				unset($_SESSION['captcha']);
				$message = array('msg'=>'感谢您的留言，核对后会尽快联系您！', "close"=>1, "clear"=>1, "sec"=>2000, 'result'=>1);
				if($postdata["nomsg"])
					unset($message["msg"]);
				if($postdata["remsg"])
					$message["msg"] = $postdata["remsg"];
				if($postdata["tourl"])
					$message["url"] = $postdata["tourl"];
				if($postdata["reload"])
					$message["reload"] = 1;
				echo json_encode($message);
				exit();
			}catch(Exception $e){
				$message = array('msg'=>$e->getMessage() ,'result'=>0);
				echo json_encode($message);
				exit();
			}
		}
	}
	
	function service(){
		$this->c_defaultlist();
		$service = spClass('service');
		if($_SERVER['REQUEST_METHOD'] == 'POST'){
			try {
				import("Common.php");
				$postdata = $this->spArgs();
				$data = array();
				//客户端提交方法
				$data['name'] = $postdata['name'];
				$data['telephone'] = $postdata['telephone'];
				$data['email'] = $postdata['email'];
				$data['question'] = $postdata['question'];
				$data['ipaddress'] = Common::GetIP();
				$data['imgfile1'] = $postdata["postimgfile1"];
				$data['imgfile2'] = $postdata["postimgfile2"];
				$data['imgfile3'] = $postdata["postimgfile3"];
				$data['createtime'] = time();
				$data['verify'] = $postdata['verify'];
				if(!$data['verify'])
					throw new Exception("请输入验证码");
				if (strtolower($data['verify']) !== strtolower($_SESSION['captcha']))
					throw new Exception('验证码不正确,请重新输入！');
				if($result = $service->spValidator($data)) {
					foreach($result as $item)
						throw new Exception($item[0]);
				}
				/*
				if(!preg_match('/^[A-Za-z0-9]+([._\-\+]*[A-Za-z0-9]+)*@([A-Za-z0-9-]+\.)+[A-Za-z0-9]+$/', $data['email']))
					throw new Exception("请输入正确的邮箱格式");
				*/
				if(!preg_match('/(^([0-9]{3}-)?(2|8)[0-9]{7}$|^(13[0-9]|15[0-9]|18[0-9])[0-9]{8}$)/',$data['telephone']))
					throw new Exception("请输入11位正确的手机号码");
				unset($data['verify']);
				if(!$service->create($data))
					throw new Exception('工单提交失败,请稍后再试！');
				unset($_SESSION['captcha']);
				$message = array('msg'=>'工单提交成功，我们会尽快联系您！', "close"=>1, "clear"=>1, "sec"=>2000, 'result'=>1);
				if($postdata["nomsg"])
					unset($message["msg"]);
				if($postdata["remsg"])
					$message["msg"] = $postdata["remsg"];
				if($postdata["tourl"])
					$message["url"] = $postdata["tourl"];
				if($postdata["reload"])
					$message["reload"] = 1;
				echo json_encode($message);
				exit();
			}catch(Exception $e){
				$message = array('msg'=>$e->getMessage() ,'result'=>0);
				echo json_encode($message);
				exit();
			}
		}
		$this->parenttitle = "售后服务";
		$this->validator = $service->getValidatorJS();
		$this->headertitle = "售后服务-";
		$this->saveurl = spUrl("main", "service");
	}
	
	public function ajaxfile(){
		import("Common.php");
		$file = $this->spArgs("file");
		$back = $this->spArgs("back");
		try {
			if(!$_FILES[$file]['name'])
				throw new Exception("请先选择要上传的文件，再进行上传");
			$res = array("result"=>1);
			$filename = basename($_FILES[$file]['name']);
			$file_ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
			if($ext_array && !in_array($file_ext, array("jpg", "gif", "png")))
				throw new Exception("请上传后缀为 jpg,gif,png 的文件");
			$file_name = Common::randomkeys(10).".$file_ext";
			$dir_str = "uploads/service/" . date("Y/m/d") . "/";
			$file_dir = $back ? "../".$dir_str : $dir_str;
			if(!is_dir($file_dir)){
				Common::rmkdir($file_dir);
				chmod($file_dir, 0755);
			}
			if(move_uploaded_file($_FILES[$file]['tmp_name'], $file_dir.$file_name)){
				$res["imgurl"] = $dir_str.$file_name;
				$res["file_id"] = $file;
				$res["result"] = 1;
			}else
				throw new Exception("未知错误，上传失败");
			echo json_encode($res);
			exit();
		}catch(Exception $e){
			echo json_encode(array("msg"=>$e->getMessage(), "result"=>0));			
			exit();
		}
	}
	
	function reservesave(){
		if($_SERVER['REQUEST_METHOD'] == 'POST'){
			try {
				$obj = spClass('reserve');
				import("Common.php");
				$postdata = $this->spArgs();
				if(!$isagree = intval($postdata["isagree"]))
					throw new Exception("如不同意协议无法提交");
				$data = array();
				//客户端提交方法
				$data['name'] = $postdata['name'];
				$data['school'] = $postdata['school'];
				$data['wechat'] = $postdata['wechat'];
				$data['idcard'] = $postdata['idcard'];
				$data['sex'] = intval($postdata['sex']);
				$data['isold'] = intval($postdata['isold']);
				$data['telephone'] = $postdata['telephone'];
				$data['qq'] = $postdata['qq'];
				$data['profession'] = "";
				if($postdata['profession'])
					$data['profession'] = implode(",", $postdata['profession']);
				$data['classlevel'] = "";
				if($postdata['classlevel'])
					$data['classlevel'] = implode(",", $postdata['classlevel']);
				$data['knowfrom'] = "";
				if($postdata['knowfrom'])
					$data['knowfrom'] = implode(",", $postdata['knowfrom']);
				$data['intention_school'] = $postdata['intention_school'];
				$data['liuyan'] = $postdata['liuyan'];
				$data['ipaddress'] = Common::GetIP();
				$data['createtime'] = time();
				if($result = $obj->spValidator($data)) {
					foreach($result as $item)
						throw new Exception($item[0]);
				}
				if(!$obj->create($data))
					throw new Exception('提交失败,请稍后再试！');
				$url = $_SERVER['HTTP_REFERER'];
				$message = array('msg'=>'感谢您的提交，信息审核后我们会尽快联系您！', "nojump"=>1, "sec"=>2000, "close"=>1,'result'=>1);
				echo json_encode($message);
				exit();
			}catch(Exception $e){
				$message = array('msg'=>$e->getMessage() ,'result'=>0);
				echo json_encode($message);
				exit();
			}
			
		}
	}
	
	//接口方法	
	protected function c_default(){
		$this->c_gettoprs();
	}
	
	private function c_default404(){
		if ($_SERVER['REQUEST_URI'] !== WEB_ROOT."/" && strpos($_SERVER['REQUEST_URI'], WEB_ROOT."/"."index.php") === false) {
			$url = WEB_ROOT."/nofound.php";
			@header("location: $url");
			exit();
		}
	}
	
	protected function c_defaultlist(){
		$id = intval($this->spArgs("id"));
		$products = spClass('article');
		$articlestyle = spClass('articlestyle');
		if ($nowtitle_rs = $articlestyle->findByPk($id, "sname, parentid")) {
			$this->nowtitle = $nowtitle_rs['sname'];
		}
		$parentid = intval($nowtitle_rs["parentid"]);
		if ($parenttitle_rs = $articlestyle->findByPk($parentid, "sname")) {
			$this->parenttitle = $parenttitle_rs['sname'];
		}
		if ($parentid) {
			$articlestyle_rs = $articlestyle->findAll(array("parentid"=>$parentid), "`columnorder` asc, sid asc", "sid, sname, islist");
			$this->leftstyle_rs = $articlestyle_rs;
			$this->parentid = $parentid;
		}
	}
	
	private function c_defaultdetail(){
		$id = intval($this->spArgs("id"));
		$products = spClass('article');
		$articlestyle = spClass('articlestyle');
		$type_rs = $products->findByPk($id, "ptype");
		$cid = $type_rs['ptype'];
		$products_rs = $products->findByPk($id, "ptype");
		$type = $products_rs['ptype'];
		$parent_rs = $articlestyle->findByPk($type, "parentid, linkfield");
		$parentid = intval($parent_rs["parentid"]);
		if ($parenttitle_rs = $articlestyle->findByPk($parentid, "sname")) {
			$this->parenttitle = $parenttitle_rs['sname'];
		}
		if ($parentid) {
			$articlestyle_rs = $articlestyle->findAll(array("parentid"=>$parentid), "`columnorder` asc, sid asc", "sid, sname, islist");
			foreach ($articlestyle_rs as $key => $val){
				if ($val['islist'] == 0) {
					if ($products_rs = $products->find(array("ptype"=>$val['sid']), null, "pid")) {
						$articlestyle_rs[$key]['pid'] = intval($products_rs['pid']);
					}
				}
			}
			$this->leftstyle_rs = $articlestyle_rs;
		}
	}
	
	private function c_defaulthtmlupdate(){
		
	}
	
	private function c_defaultaddhtmlurl(){
		
	}
	
	private function c_defaultaddsitemapurl(){
		
	}
	
	private function c_gettoprs(){
		$articlestyle = spClass('articlestyle');
		$condition = array("frontdisplay"=>1);
		if ($list_rs = $articlestyle->findAll(null, null, "sid, islist, outlink")) {
			foreach ($list_rs as $key => $val){
				if ($val['outlink']) {
					$root_columnurl[$val['sid']] = $columnurl[$val['sid']] = substr($val['outlink'],0,7) !== "http://" ? WEB_ROOT."/".$val['outlink'] : $val['outlink'];
					continue;
				}
				if ($val['islist'] == 0) {
					$columnurl[$val['sid']] = spUrl("main", "cdetail", array("id"=>$this->getonpageid($val['sid'])));
				}else{
					$columnurl[$val['sid']] = spUrl("main", "clist", array("id"=>$val['sid']));
				}
				$root_columnurl[$val['sid']] = str_replace(WEB_ROOT . "/" . ENT_MARK, WEB_ROOT, $columnurl[$val['sid']]);
			}
			$this->columnurl = $columnurl;
			$this->root_columnurl = $root_columnurl;
		}
	}
	
	private function check_entrance($column_rs){
		if(!$column_rs["isentrance"] && ENT_MARK != "ENT_MARK"){
			header("location:".str_replace(ENT_MARK . "/", "", 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']));
			exit();
		}
		if($column_rs["isentrance"] && ENT_MARK == "ENT_MARK"){
			$obj_ent = spClass("entrance");
			if(!$ent_rs = $obj_ent->getinfoById($column_rs["isentrance"]))
				return true;
			header("location:".str_replace(WEB_ROOT . "/", WEB_ROOT . "/" . $ent_rs["mark"] . "/", 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']));
			exit();
		}
	}
	
	//系统方法
	function clist(){
		$this->c_defaultlist();
		$postdata = $this->spArgs();
		$id = intval($postdata["id"]);
		$pid = intval($postdata["pid"]);
		$fpid = intval($postdata["fpid"]);
		$f = intval($postdata["f"]); //隶属id
		$l = intval($postdata["l"]); //关联id
		$keys = urldecode($postdata["keys"]);
		$products = spClass('article');
		$productcato = spClass('articlecato');
		$articlestyle = spClass('articlestyle');
		$obj_extval = spClass("article_extval");
		$obj_filter = spClass("articlefilter");
		$obj_photo = spClass('photos');
		$obj_cover = spClass('article_coverconfig');
        $obj_video = spClass("article_video");
		if ($id && $column_rs = $articlestyle->find(array("sid"=>$id))) {
			$this->check_entrance($column_rs);
			switch ($column_rs["parentid"]){
				case 0:
					$this->main_column_rs = $this->column_rs = $column_rs;
					$headertitle = $column_rs['sname']."_" ;
					if ($main_column_rs = $articlestyle->find(array("sid"=>$column_rs['sid'], "parentid"=>0)))
						$this->main_column_rs = $main_column_rs;
				break;
				default:
					$page = intval(max($postdata['page'], 1));
					if(!$column_rs['pagesize']) $column_rs['pagesize'] = 20;
					$listcondition = $this->sys_entid ? "hnyn_articles.entrance_id = $this->sys_entid" : "1";
					$listcondition .= " and hnyn_articles.ishide = 0 and hnyn_articles.specrecomd = 0 and hnyn_articles.ptype = $id";
					if ($pid > 0) {
						$listcondition .= " and hnyn_articles.pc_id = $pid";
					}
					if ($fpid > 0) {
						$listcondition .= " and hnyn_articlescato.fid = $fpid";
						$this->fpid = $fpid;
						$this->main_cato_rs = $productcato->find(array("pc_id"=>$fpid));
						$this->cato2_rs = $productcato->findAll(array("fid"=>$fpid), "`order` asc");
					}
					if ($f > 0) {
						$listcondition .= "and hnyn_articles.subproduct = $f";
						$this->f_rs = $products->findByPk($f, "pid, name");
					}
					if ($l > 0) {
						$listcondition .= " and find_in_set($l, hnyn_articles.relatestr)";
						$this->f_rs = $products->findByPk($l, "pid, name");
					}
					if ($keys) {
						$listcondition .= " and hnyn_articles.name like '%".$keys."%'";
						$this->keys = $keys;
					}
					if($column_rs['isfilter2'] && strpos($_SERVER["REQUEST_URI"], "filter_")){
						$url_arary = parse_url($_SERVER["REQUEST_URI"]);
						$query = $url_arary["query"];
						if($query_array = explode("&", $query)){
							foreach($query_array as $val){
								if(strpos($val, "filter_") !== false){
									$arg_array = explode("=", $val);
									$arg_1_array = explode("_", $arg_array[0]);
									$postdata[$arg_1_array[0]][$arg_1_array[1]] = $arg_array[1];
								}
							}
						}
						foreach($postdata["filter"] as $key=>$val){
							$filter_name_rs = $obj_filter->join("hnyn_articlesfilter as pfilter", "pfilter.pc_id = hnyn_articlesfilter.belong_id")->find(array("hnyn_articlesfilter.pc_id"=>$val), null, "hnyn_articlesfilter.belong_id, hnyn_articlesfilter.pc_name, pfilter.parent_id");
							if(intval($val) > 0 && $filter_name_rs && (!$filter_name_rs["parent_id"] || in_array($filter_name_rs["parent_id"], $postdata["filter"]))){
								$filter_name[$filter_name_rs["fid"]] = $filter_name_rs["pc_name"];
								$filter_condition .= " and find_in_set(".intval($val).", filter2_id)";
							}else{
								$postdata["filter"][$key] = 0;
							}
							$extpager .= "&filter[$key]=$val";
						}
						$this->filter_name = $filter_name;
						$this->extpager = $extpager;
					}
					$sort = "hnyn_articles.`top` desc, hnyn_articles.`recomd` desc, hnyn_articles.stj_hot desc, hnyn_articles.stj_news desc, hnyn_articles.stj_soldout asc, hnyn_articles.`specrecomd` desc, hnyn_articles.`order` asc, hnyn_articles.`status` desc, hnyn_articles.`posttime` desc, hnyn_articles.`pid` desc";
					$p_rs = $products->join("hnyn_articlescato", "hnyn_articles.pc_id = hnyn_articlescato.pc_id", "left")->spPager($page, $column_rs['pagesize'])->findAll($listcondition.$filter_condition, $sort, "hnyn_articles.pid, hnyn_articles.name, hnyn_articles.description, hnyn_articles.short, hnyn_articles.fname, hnyn_articles.picurlpath, hnyn_articles.picurlfile, hnyn_articles.picurlpath2, hnyn_articles.picurlfile2, hnyn_articles.link, hnyn_articles.linkpic, hnyn_articles.posttime, hnyn_articles.extinput, hnyn_articles.`top`, hnyn_articles.`order`, hnyn_articles.`status`, hnyn_articles.pc_id, hnyn_articles.hits, hnyn_articles.price, hnyn_articlescato.fid as fpid, hnyn_articlescato.pc_name, hnyn_articles.filter2_id, hnyn_articles.relatestr");
					if($p_rs && $column_rs['iscover'])
						$topCover_rs = $obj_cover->getToplist($column_rs["sid"]);
					foreach ($p_rs as $key => $val){
						if($column_rs["is_extfield"]) $p_rs[$key]["extfield"] = $obj_extval->extval_get_mark($val["pid"]);
						if ($val['extinput']) $p_rs[$key]['extinput'] = unserialize($val['extinput']);
						$p_rs[$key]['thumb'] = $val['picurlfile'] ? $val['picurlpath']."thumb_".$val['picurlfile'] : "images/blank.png";
						$p_rs[$key]['pic'] = $val['picurlfile'] ? $val['picurlpath'].$val['picurlfile'] : "images/blank.png";
						$p_rs[$key]['thumb2'] = $val['picurlfile2'] ? $val['picurlpath2']."thumb_".$val['picurlfile2'] : "images/blank.png";
						$p_rs[$key]['pic2'] = $val['picurlfile2'] ? $val['picurlpath2'].$val['picurlfile2'] : "images/blank.png";
						if ($val['description']) $p_rs[$key]['sub_description'] = $this->removehtml($val['description'], 1000);
						if ($val['posttime']) $p_rs[$key]["ftime"] = date("Y-m-d", strtotime($val['posttime']));
                        if($column_rs["isvideo"]){
                            $p_rs[$key]["video_rs"] = $obj_video->getShowInfoFromArticle($val['pid'], 1);
                        }
						if($topCover_rs){
							foreach ($topCover_rs as $k => $v){
								$p_rs[$key]["cover"][$v["cover_mark"]] = "";
								$cover_mark_group = array();
								if($photo_rs = $obj_photo->findAll(array("cover_id"=>$v["id"], "pro_id"=>$val["pid"]), "`order` asc", "name, concat(filepath, filename) as img, concat(filepath, 'thumb_', filename) as thumb"))
									$p_rs[$key]["cover"][$v["cover_mark"]] = $photo_rs;
							}
						}
						$p_rs[$key]['turl'] = $val["link"] && $val["link"] != 'NULL' ? str_replace("__url__", $_SERVER['HTTP_HOST'], strtolower($val["link"])) : spUrl("main", "cdetail", array("id"=>$val['pid']));
						if($val["filter2_id"] && $column_rs['isfilter2']){
							if($filter_rs = $obj_filter->findAll("pc_id in({$val["filter2_id"]}) and belong_id <> 0", null, "pc_id, belong_id, pc_name")){
								foreach($filter_rs as $k => $v){
									$p_rs[$key]["thisfilter"][$v["fid"]][] = array("pc_id"=>$v["pc_id"], "pc_name"=>$v["pc_name"]);
								}
							}
						}
					}
					if($pid)
						$this->cato_rs = $productcato->findByPk($pid);
					if($column_rs['isfilter2']){
						$filter_array = array();
						if($filter_id_rs = $products->findAll($listcondition.$filter_condition, null, "filter2_id")){
							foreach($filter_id_rs as $val){
								if($val["filter2_id"]){
									$temp_array = explode(",", $val["filter2_id"]);
									$filter_array = array_merge($filter_array, $temp_array);
								}
							}
						}
						$all_filter_array = array();
						if($all_id_rs = $products->findAll($listcondition, null, "filter2_id")){
							foreach($all_id_rs as $val){
								if($val["filter2_id"]){
									$all_temp_array = explode(",", $val["filter2_id"]);
									$all_filter_array = array_merge($all_filter_array, $all_temp_array);
								}
							}
						}
						$filter_array_condition = $filter_array ? "hnyn_articlesfilter.pc_id in(".implode(',',$filter_array).")" : "0";
						$all_filter_array_condition = $all_filter_array ? "hnyn_articlesfilter.pc_id in(".implode(',',$all_filter_array).")" : "0";
						//if($filter_rs = $obj_filter->join("hnyn_articlesfilter as pfilter", "pfilter.pc_id = hnyn_articlesfilter.belong_id")->findAll("if(pfilter.is_noresultfilter, $all_filter_array_condition, $filter_array_condition) and hnyn_articlesfilter.markid = $id", "pfilter.is_recommend desc, pfilter.`order` asc, pfilter.pc_id desc", "pfilter.pc_id, pfilter.pc_name, pfilter.parent_id", "pfilter.pc_id")){
						if($filter_rs = $obj_filter->join("hnyn_articlesfilter as pfilter", "pfilter.pc_id = hnyn_articlesfilter.parent_id", "left")->findAll("hnyn_articlesfilter.belong_id = 0 and hnyn_articlesfilter.markid = $id", "hnyn_articlesfilter.is_recommend desc, hnyn_articlesfilter.`order` asc, hnyn_articlesfilter.pc_id desc", "hnyn_articlesfilter.pc_id, hnyn_articlesfilter.pc_name, hnyn_articlesfilter.parent_id, pfilter.belong_id as p_fid")){
							$sub_filter_id = array();
							foreach($filter_rs as $key => $val){
								if(!$val["parent_id"]){
									if($filter_sub_rs = $obj_filter->join("hnyn_articlesfilter as pfilter", "pfilter.pc_id = hnyn_articlesfilter.belong_id")->findAll("if(pfilter.is_noresultfilter, $all_filter_array_condition, $filter_array_condition) and hnyn_articlesfilter.belong_id = $val[pc_id]", "hnyn_articlesfilter.is_recommend desc, hnyn_articlesfilter.`order` asc, hnyn_articlesfilter.pc_id desc", "hnyn_articlesfilter.*"))
										$filter_rs[$key]["sub"] = $filter_sub_rs;
								}elseif($val["parent_id"])
									if(in_array($val["parent_id"], $postdata["filter"])){
										if($filter_sub_rs = $obj_filter->join("hnyn_articlesfilter as pfilter", "pfilter.pc_id = hnyn_articlesfilter.belong_id")->findAll("if(pfilter.is_noresultfilter, $all_filter_array_condition, $filter_array_condition) and hnyn_articlesfilter.belong_id = $val[pc_id]", "hnyn_articlesfilter.is_recommend desc, hnyn_articlesfilter.`order` asc, hnyn_articlesfilter.pc_id desc", "hnyn_articlesfilter.*"))
											$filter_rs[$key]["sub"] = $filter_sub_rs;
										$sub_filter_id[] = $val["p_fid"];
									}elseif(!$val["p_fid"] && !in_array($val["p_fid"], $sub_filter_id)){
										if($filter_sub_rs = $obj_filter->join("hnyn_articlesfilter as pfilter", "pfilter.pc_id = hnyn_articlesfilter.belong_id")->findAll("hnyn_articlesfilter.belong_id = $val[pc_id]", "hnyn_articlesfilter.is_recommend desc, hnyn_articlesfilter.`order` asc, hnyn_articlesfilter.pc_id desc", "hnyn_articlesfilter.*"))
											$filter_rs[$key]["sub"] = $filter_sub_rs;
									}else
										unset($filter_rs[$key]);
							}
							/*
							print_r($sub_filter_id);
							print_r($filter_rs);
							*/
							if($sub_filter_id){
								foreach($sub_filter_id as $key => $val)
									unset($filter_rs[$val]);
							}
							$this->filter_rs = $filter_rs;
						}
						$this->filter = $postdata["filter"];
					}
					if ($main_column_rs = $articlestyle->find(array("sid"=>$column_rs['parentid'], "parentid"=>0)))
						$this->main_column_rs = $main_column_rs;
					$this->c = "main";
					$this->a = "clist";
					$this->pageid = $id;
					$this->pager = $products->spPager()->getPager();
					$this->column_rs = $column_rs;
					$this->list_rs = $p_rs;
					$this->pid = $pid;
					$this->f = $f;
					$this->l = $l;
					$headertitle = (($column_rs['sname'] == $main_column_rs['sname']) || ($main_column_rs['sid'] == 6)) ? $column_rs['sname']."_" : $column_rs['sname']."_".$main_column_rs['sname']."_";
					if($this->cato_rs)
						$headertitle = $this->cato_rs["pc_name"]."_".$headertitle;
				break;
			}
			if($this->f_rs) $headertitle.= $this->f_rs['name']."_";
			$this->headertitle = $headertitle;
			$this->nowurl = $_SERVER["REQUEST_URI"];
			if($column_rs["iscato"] && $this->list_index && !$pid){
				$this->display("customfolder/".$this->list_index_template);
			}
			if ($column_rs['displaylist']) {
				$this->display("customfolder/".$column_rs['displaylist']);
			}
		}else{
			//$this->redirect(spUrl("main", "index"), "找不到该页！");
			$url = WEB_ROOT."/"."nofound.php";
			@header("location: $url");
			exit();
		}
	}
	
	function cdetail(){
		$this->c_defaultdetail();
		$postdata = $this->spArgs();
		$id = intval($postdata["id"]);
		$products = spClass('article');
		$productcato = spClass('articlecato');
		$obj_photo = spClass('photos');
		$articlestyle = spClass('articlestyle');
		$obj_filter = spClass('articlefilter');
		$obj_extval = spClass("article_extval");
		$obj_cover = spClass('article_coverconfig');
		$obj_spec = spClass('article_spec');
		$obj_args = spClass('article_spec_args');
		$obj_video = spClass("article_video");
		if ($id && $info_rs = $products->find(array("pid"=>$id, "ishide"=>"0"))) {
			if (!$column_rs = $articlestyle->find(array("sid"=>$info_rs['ptype'], "parentid <>"=>0))) {
			 	$this->redirect(spUrl("main", "index"), "找不到该页！");
			}
			$this->check_entrance($column_rs);
			if($info_rs['pc_id']){
				$this->cato_rs = $productcato->findByPk($info_rs['pc_id']);
			}
			if($info_rs["relatestr"]){
				if($relate_rs = $products->findAll("pid in({$info_rs["relatestr"]})")){
					foreach($relate_rs as $key => $val){
						if ($val['picurlfile']) $relate_rs[$key]['thumb'] = $val['picurlfile'] ? $val['picurlpath']."thumb_".$val['picurlfile'] : "";
						if ($val['picurlfile']) $relate_rs[$key]['pic'] = $val['picurlfile'] ? $val['picurlpath'].$val['picurlfile'] : "";
						$relate_rs[$key]['turl'] = $val["link"] && $val["link"] != 'NULL' ? str_replace("__url__", $_SERVER['HTTP_HOST'], strtolower($val["link"])) : spUrl("main", "cdetail", array("id"=>$val['pid']));
					}
				}
				$info_rs["relate_rs"] = $relate_rs;
			}
			if ($info_rs['extinput']) {
				$info_rs['extinput'] = unserialize($info_rs['extinput']);
				foreach($info_rs['extinput'] as $key => $val){
					$info_rs['extinput'][$key] = str_replace("../upload/", WEB_ROOT.'/upload/', $val);
				}
			}
			if($column_rs['isfilter2'] && $info_rs["filter2_id"]){
				if($topFilter_rs = $obj_filter->getToplist($column_rs["sid"])){
					foreach ($topFilter_rs as $key => $val){
						$info_rs["filter"][$val["filter_mark"]] = "";
						$filter_mark_group = array();
						$filter_mark_id_group = array();
						if($filter_rs = $obj_filter->join("hnyn_articlesfilter as pfilter", "pfilter.pc_id = hnyn_articlesfilter.belong_id")->findAll("pfilter.filter_mark = '" . $val["filter_mark"] . "' and hnyn_articlesfilter.pc_id in(" . $info_rs["filter2_id"] . ") and hnyn_articlesfilter.belong_id > 0", "hnyn_articlesfilter.`order` asc", "hnyn_articlesfilter.pc_id, hnyn_articlesfilter.pc_name")){
							foreach($filter_rs as $k=>$v){
								$filter_mark_group[] = $v["pc_name"];
								$filter_mark_id_group[] = $v["pc_id"];
							}
							$info_rs["filter"][$val["filter_mark"]] = implode(",", $filter_mark_group);
							$info_rs["filter_id"][$val["filter_mark"]] = implode(",", $filter_mark_id_group);
						}
					}
				}
			}
			if($info_rs['description']!=''){
				$info_rs['description'] = str_replace('/upload/', URL_ROOT.'/upload/', $info_rs['description']);
			}
			if($info_rs['description2']!=''){
				$info_rs['description2'] = str_replace('/upload/', URL_ROOT.'/upload/', $info_rs['description2']);
			}
			if($info_rs['picurlfile']){
				$info_rs['img'] = $info_rs['picurlpath'] . $info_rs['picurlfile'];
				$info_rs['thumb'] = $info_rs['picurlpath'] . "thumb_" . $info_rs['picurlfile'];
			}
			if($column_rs['iscover']){
				if($topCover_rs = $obj_cover->getToplist($column_rs["sid"])){
					foreach ($topCover_rs as $key => $val){
						$info_rs["cover"][$val["cover_mark"]] = "";
						$cover_mark_group = array();
						$photo_rs = array();
						if($photo_rs = $obj_photo->findAll(array("cover_id"=>$val["id"], "pro_id"=>$id), "`order` asc", "name,fname,short,description, concat(filepath, filename) as img, concat(filepath, 'thumb_', filename) as thumb, turl"))
							$info_rs["cover"][$val["cover_mark"]] = $photo_rs;
						else 
							unset($info_rs["cover"][$val["cover_mark"]]);
					}
				}
			}
			if($column_rs["is_extfield"]){
				$info_rs["extfield"] = $obj_extval->extval_get_mark($id);
			}
			if($column_rs["isspecifications"]){
				$info_rs["spec_rs"] = $obj_spec->getlist($id);
			}
			if ($GLOBALS['spConfig']['ext']['zxtag']['enabled']) {
				import("zxtag.php");
				if(preg_match_all('/#(.*?)#/', $info_rs['description'], $matches)) {
					foreach($matches[1] as $func_key => $func_name){
						eval('$zxtag[\''.$func_key.'\'] = @ZTag::'.$func_name.";");
						$info_rs['description'] = str_replace($matches[0][$func_key], $zxtag[$func_key], $info_rs['description']);
					}
				}
			}
			if($info_rs["tagstr"]){
				$info_rs["tagarray"] = explode(",", $info_rs["tagstr"]);
			}
			if($info_rs["entrance_id"]){
				$obj_entrance = spClass("entrance");
				$entrance_rs = $obj_entrance->findByPk($info_rs["entrance_id"]);
				$info_rs["entrance_name"] = $entrance_rs["name"];
			}
			if($info_rs["entrance_line_id"]){
				$obj_entrance_line = spClass("entrance_line");
				$entrance_line_rs = $obj_entrance_line->findByPk($info_rs["entrance_line_id"]);
				$info_rs["entrance_line_name"] = $entrance_line_rs["name"];
				$info_rs["entrance_line_app_id"] = $entrance_line_rs["app_id"];
			}
			if($info_rs["filter2_id"] && $column_rs['isfilter2']){
				if($filter_rs = $obj_filter->findAll("pc_id in({$info_rs["filter2_id"]}) and belong_id <> 0", null, "pc_id, belong_id, pc_name")){
					foreach($filter_rs as $k => $v){
						$info_rs["thisfilter"][$v["fid"]][] = array("pc_id"=>$v["pc_id"], "pc_name"=>$v["pc_name"]);
					}
				}
			}
			$video_rs = $obj_video->getShowInfoFromArticle($info_rs['pid'], 1);
            $info_rs["videourl"] = $video_rs["filepath"];
			$this->info_rs = $info_rs;
			$this->column_rs = $column_rs;
			if ($main_column_rs = $articlestyle->find(array("sid"=>$column_rs['parentid'], "parentid"=>0))) {
				$this->main_column_rs = $main_column_rs;
			}
			$headertitle = $column_rs['sname'] == $main_column_rs['sname'] ? $column_rs['sname']."_" : $column_rs['sname']."_".$main_column_rs['sname']."_";
			if($this->cato_rs)
				$headertitle = $this->cato_rs["pc_name"]."_".$headertitle;
			if($column_rs['islist'])
				$headertitle = $info_rs['name']."_".$headertitle;
			$this->headertitle = $headertitle;
			$this->adapter_mobile = "1";
			$this->id = $id;
			$this->p = intval($postdata["p"]);
			/*
			if($filter2_id = $p_rs["filter2_id"]){
				$filter2_array = explode(",",$filter2_id);
				if(in_array(16, $filter2_array))
					$this->display("customfolder/info_senior_land.html");
			}
			*/
			$display_str = $column_rs['displaydetail'] ? "customfolder/".$column_rs['displaydetail'] : "main/cdetail.html";
			if($column_rs["isbranch"] && $info_rs["branch"]){
				$obj_branch = spClass('article_branch');
				$branch_rs = $obj_branch->find("id = {$info_rs["branch"]}", null, "mark");
				$display_str = str_replace(".html", "_".$branch_rs["mark"].".html", $display_str);
			}
			$this->display($display_str);
		}else{
			$url = WEB_ROOT."/"."nofound.php";
			@header("location: $url");
			exit();
		}
	}
	
	public function download(){
		try {
			$products = spClass('article');
			$obj_extfield = spClass("article_extfield");
			if(!$id = intval($this->spArgs("id")))
				throw new Exception("必要参数错误");
			if(!$article_rs = $products->find(array("pid"=>$id), null, "name, packageurl"))
				throw new Exception("找不到该新闻，可能已被删除");
			if(!$act = $this->spArgs("act"))
				throw new Exception("行为参数错误");
			if($ext = intval($this->spArgs("ext"))){
				if(!$rs = $obj_extfield->join("hnyn_articlesextfieldtype")->join("hnyn_articlesextval")->find(array("hnyn_articlesextfieldtype.type_mark"=>"file", "hnyn_articlesextval.article_id"=>$id, "hnyn_articlesextfield.field_mark"=>$act), null, "field_val"))
					throw new Exception("找不到该附件地址");
				if(!$rs["field_val"])
					throw new Exception("暂没有对应的附件，下载失败");
				$fileurl = $rs["field_val"];
				$name = "source_".$id."_".$act;
			}else{
				if(!$article_rs["packageurl"])
					throw new Exception("暂没有对应的附件，下载失败");
				$fileurl = $article_rs["packageurl"];
				$name = "source_".$id."_packageurl";
			}
			$file_ext = strtolower(substr($fileurl, strrpos($fileurl, '.') + 1));
			import("download.php");
			$obj_down = new FileDownload();
			$flag = $obj_down->download($fileurl, $name.".".$file_ext);
			//$flag = FileDownload::download($fileurl, $name.".".$file_ext); // 断点续传
			if(!$flag)
				throw new Exception("找不到该附件，可能已被删除");
		}catch(Exception $e){
			$this->redirect(spUrl("main", "index"), $e->getMessage());
			exit();
		}
	}
	
	public function getcato2(){
		$postdata = $this->spArgs();
		$markid = intval($postdata['cid']);
		$fid = intval($postdata['fid']) ? intval($postdata['fid']) : -1;
		$productcatos = spClass('articlecato');
		$this->cato_rs = $productcatos->findAll(array("fid"=>$fid, "markid"=>$markid), "");
		$return['body'] = $this->fetch('ajaxcatoselect.html');
		echo json_encode($return);
		exit();
	}
	
	public function zparea(){
		$postdata = $this->spArgs();
		$pc_id = intval($postdata['pc_id']);
		$productcatos = spClass('articlecato');
		//$productcatos->debug(1);
		if($cato_rs = $productcatos->join("hnyn_articlescato as f", "hnyn_articlescato.fid = f.pc_id")->find(array("hnyn_articlescato.pc_id"=>$pc_id), null, "hnyn_articlescato.*, f.pc_name as fname")){
			echo "document.write('$cato_rs[fname]-$cato_rs[pc_name]')";
		}else{
			echo "document.write('未分组')";
		}
		exit();
	}

	public function getspecargs(){
		try{
			$obj_spec = spClass('article_spec');
			$obj_group = spClass('article_spec_group');
			$obj_args = spClass('article_spec_args');
			$postdata = $this->spArgs();
			if(!$id = intval($postdata["id"]))
				throw new Exception("新闻参数丢失");
			if(!$spec_id = intval($postdata["spec_id"]))
				throw new Exception("规格参数丢失");
			if(!$spec_rs = $obj_spec->find(array("id"=>$spec_id, "article_id"=>$id, "isdel"=>0)))
				throw new Exception("参数错误");
			$html = "";
			if(!$group_rs = $obj_group->findAll(array("spec_id"=>$spec_id, "isdel"=>0), "`sort` asc")){
				$html .= '<div class="pro_n_pro_con_name">无规格参数</div>';
			}else{
				foreach($group_rs as $key => $val){
                    $args_group_lr = ($key % 2 == 0) ? "args_group_left" : "args_group_right";
                    $args_str = "";
                    if($args_rs = $obj_args->findAll(array("group_id"=>$val["id"]), "sort asc")){
                        foreach($args_rs  as $k => $v){
                            $en_title = $v["name_en"] ? "<span class='args_group_box_title_en'>{$v["name_en"]}：</span>" : "";
                            $args_str .= <<<EOF
<div class="args_group_box">
    <div class="args_group_box_cell">
        <span class="args_group_box_title">
            {$v["name"]}：
        </span>
        {$en_title}
    </div>
    <div class="args_group_box_value">
        {$v["val"]}
    </div>
</div>
EOF;
                        }
                    }
					$html .= <<<EOF
<div class="{$args_group_lr}">
    <div class="args_group_header">
        {$val["name"]}
    </div>
    {$args_str}
</div>
EOF;
				}
			}
			$message = array("html"=>$html, 'msg'=>'success','result'=>1);
			echo json_encode($message);
			exit();
		}catch(Exception $e){
			$message = array("html"=>"", 'msg'=>$e->getMessage(), 'result'=>0);
			echo json_encode($message);
			exit();
		}
	}
	
	public function sitemap(){
		global $spConfig;
		$products = spClass('article');
		$productcatos = spClass('articlecato');
		$articlestyle = spClass('articlestyle');
		$obj_ent = spClass("entrance");
		if($spConfig["entrance"]["enabled"])
			$ent_rs = $obj_ent->getlist();
		//网站首页
		$sitemapurl[] = array(
			WEB_ROOT . "/", 
			$this->app_config['website_name'], 
			date("Y-m-d"), 
			"Daily",
			"1.0"
		);
		//各个入口首页
		if($ent_rs){
			foreach($ent_rs as $val){
				$sitemapurl[] = array(
					WEB_ROOT ? str_replace(WEB_ROOT, WEB_ROOT."/".$val["mark"], spUrl("main", "index")) : "/".$val["mark"].spUrl("main", "index"),
					$val["name"] . "国家频道_" . $this->app_config['website_name'],
					date("Y-m-d"),
					"Always",
					"1.0"
				);
			}
		}
		//各栏目列表地址
		
		if ($articlestyle_rs = $articlestyle->findAll(array("parentid <>"=> "0", "islist" => 1, "ishtml"=>1), "sid asc", "sid, sname, isentrance")) {
			foreach ($articlestyle_rs as $key => $val){
				if($val["isentrance"] && $ent_rs){
					foreach($ent_rs as $vv){
						$sitemapurl[] = array(
							WEB_ROOT ? str_replace(WEB_ROOT, WEB_ROOT."/".$vv["mark"], spUrl("main", "clist", array("id"=>$val['sid']))) : "/".$vv["mark"].spUrl("main", "clist", array("id"=>$val['sid'])),
							$val['sname']."_".$vv["name"] . "国家频道_" . $this->app_config['website_name'],
							date("Y-m-d"),
							"Daily",
							"0.8"
						);
					}
				}else{
					$sitemapurl[] = array(
						spUrl("main", "clist", array("id"=>$val['sid'])),
						$val['sname']. "_".$this->app_config['website_name'],
						date("Y-m-d"),
						"Daily",
						"0.8"
					);
				}
			}
		}
		//各单页地址
		if ($products_rs = $products->join("hnyn_entrance", "hnyn_entrance.id = hnyn_articles.entrance_id", "left")->join("hnyn_articlestyle", "hnyn_articlestyle.sid = hnyn_articles.ptype")->findAll(array("hnyn_articlestyle.ishtml"=>1), "hnyn_articles.pid asc", "hnyn_articles.pid, hnyn_articles.name, hnyn_articles.posttime, hnyn_entrance.mark as ent_mark")) {
			foreach ($products_rs as $key => $val){
				$sitemapurl[] = array(
					$val["ent_mark"] ? (WEB_ROOT ? str_replace(WEB_ROOT, WEB_ROOT."/".$val["ent_mark"], spUrl("main", "cdetail", array("id"=>$val["pid"]))) : "/".$val["ent_mark"].spUrl("main", "cdetail", array("id"=>$val["pid"]))) : spUrl("main", "cdetail", array("id"=>$val['pid'])), 
					$val['name']. " - ".$this->app_config['website_name'], 
					date("Y-m-d", strtotime($val["posttime"])),
					"Weekly",
					"0.9"
				);
			}
		}
		
		//各个特殊页地址
		if ($addhtmlurl = $this->c_defaultaddsitemapurl()){
			foreach($addhtmlurl as $val){
				$sitemapurl[] = $val;
			}
		}
		$this->web_root = "http://" . $_SERVER['HTTP_HOST'];
		$this->sitemapurl = $sitemapurl;
		if($this->spArgs("type") == "urls"){
			$urls = $this->fetch("main/sitemap_urls.html");
			$fp = fopen("urls.txt", "w");
			fwrite($fp, $urls);
			fclose($fp);
			header("Content-Type: text/html; charset=UTF-8");
			echo "urls.txt生成成功！";
			exit();
		}
		$this->display("../standsky/tpl/sites/sitemap.html");
	}
	
	protected function removehtml($str,$length){
		import("Common.php");
		if (!empty($str)){
			$str = strip_tags($str, '<br><br />');
			$str = str_replace("\n","",$str); 
			$str = str_replace("\r\n","",$str); 
			$str=preg_replace("/\s/","",$str);
			$str = str_replace("&nbsp;","",$str);
			$str = Common::utf8_substr(Common::trimHtml(strip_tags($str)), 0, intval($length), "");
		}
		return $str;
	}
	
	private	function getonpageid($columnid){
		$products = spClass('article');
		if ($id_rs = $products->find(array('ptype'=>$columnid), "`pid` desc", "pid")) {
			return intval($id_rs['pid']);
		}else{
			return 0;
		}
	}
	
	private	function getcolumnrs($pageid){
		$products = spClass('article');
		if ($column_rs = $products->find(array('pid'=>$pageid))) {
			return $column_rs;
		}
	}
	
	/*
	 分页全部参数应用例子
	array("main", "clist", array("id"=>$val['sid'], "pid"=>0, "f"=>"0", "l"=>"0", "page"=>$i)), $val['fmark']."/".$val['mark']."/index_$i.html"
	根据需要，配置不同参数
	*/
	function htmlupdate(){
		if (!$_SESSION['admin_user']) return false;
		if($_SERVER['REQUEST_METHOD'] == 'POST' || $this->spArgs("cache_adv") == "zx") {
			$sep = $GLOBALS['G_SP']['html']['sep'] ? $GLOBALS['G_SP']['html']['sep'] : "/";
			set_time_limit(900);
			$this->c_defaulthtmlupdate();
			$htmlurl = $this->c_defaultaddhtmlurl();
			if($_SESSION["htmlurl"] && TRUE == $GLOBALS['G_SP']['html']["enabled_zxadv"] && $this->spArgs("auto") == 1){
				$this->htmlcontinue_adv();
				$this->display("main/htmlupdate.html");
				exit();
			}
			$products = spClass('article');
			$productcatos = spClass('articlecato');
			$articlestyle = spClass('articlestyle');
			$postdata = $this->spArgs();
			$columnid = intval($postdata['list']);
			if ($columnid > 0 && !$articlestyle->findByPk($columnid)) {
				$message = array('msg'=>'找不到该栏目，可能已被删除！','result'=>0);
				echo json_encode($message);
				exit();
			}
			if ($columnid == -1) { //仅更新首页
				if(TRUE != $GLOBALS['G_SP']['html']["enabled_zxadv"])
					spClass("spHtml")->clear("main", "index", null, null, true);
				$htmlurl[] = array(
					array("main", "index"), "../index.html"
				);
			}elseif ($columnid == -2) { //仅更新sitemap
				if(TRUE != $GLOBALS['G_SP']['html']["enabled_zxadv"])
					spClass("spHtml")->clear("main", "sitemap", null, null, true);
				$htmlurl[] = array(
					array("main", "sitemap"), "../sitemap.xml"
				);
			}elseif ($columnid == 0) { //更新全部静态页
				if(!$postdata['type']){
					if(TRUE != $GLOBALS['G_SP']['html']["enabled_zxadv"])
						spClass("spHtml")->clearAll(true);
				}
				$htmlurl[] = array(
						array("main", "index"), "../index.html"
				);
				/*
				$htmlurl[] = array(
						array("main", "sitemap"), "../sitemap.html"
				);
				*/
				//生成一级栏目首页
				if(!$postdata['type'] || $postdata['type'] == 1){
					if($top_column_rs = $articlestyle->findAll("parentid = 0 and ishtml = 1 and frontdisplay = 1 and displaylist <> ''", "columnorder asc", "sid, mark")){
						foreach ($top_column_rs as $val){
							$htmlurl[] = array(
									array("main", "clist", array("id"=>$val['sid'])), $val['mark'].$sep."index.html"
							);
						}
					}
				}
				//生成列表页
				if(!$postdata['type'] || $postdata['type'] == 1){
					if ($articlestyle_rs = $articlestyle->join("hnyn_articlestyle as b", "b.sid = hnyn_articlestyle.parentid")->findAll(array("hnyn_articlestyle.parentid <>"=> "0", "hnyn_articlestyle.islist" => 1, "hnyn_articlestyle.ishtml"=>1), "hnyn_articlestyle.sid asc", "hnyn_articlestyle.sid, hnyn_articlestyle.parentid, hnyn_articlestyle.mark, hnyn_articlestyle.iscato, hnyn_articlestyle.iscato2, hnyn_articlestyle.pagesize, hnyn_articlestyle.subcolumn, hnyn_articlestyle.relatestr, b.mark as fmark")) {
						foreach ($articlestyle_rs as $key => $val){
							$htmlurl[] = array(
									array("main", "clist", array("id"=>$val['sid'])), $val['fmark'].$sep.$val['mark'].$sep."index.html"
							);
							$total_rs = $products->find(array("ptype"=>$val['sid']), null, "count(pid) as total");
							if ($total_rs['total'] > $val['pagesize']) {
								$totalpage = ceil($total_rs['total'] / $val['pagesize']);
								for ($i=1; $i<=$totalpage; $i++){
									$htmlurl[] = array(
											array("main", "clist", array("id"=>$val['sid'], "pid"=>0, "page"=>$i)), $val['fmark'].$sep.$val['mark'].$sep."index_$i.html"
									);
								}
							}
							if ($val['iscato2']) {
								if ($productcatos_rs = $productcatos->findAll(array("markid"=>$val['sid'], "fid <>" => 0), null, "pc_id")) {
									foreach ($productcatos_rs as $pkey => $pval){
										$htmlurl[] = array(
												array("main", "clist", array("id"=>$val['sid'], "pid"=>$pval['pc_id'])), $val['fmark'].$sep.$val['mark'].$sep.$pval['pc_id'].$sep."index.html"
										);
										$ptotal_rs = $products->find(array("pc_id"=>$pval['pc_id']), null, "count(pid) as total");
										if ($ptotal_rs['total'] > $val['pagesize']) {
											$totalpage = ceil($ptotal_rs['total'] / $val['pagesize']);
											for ($i=1; $i<=$totalpage; $i++){
												$htmlurl[] = array(
														array("main", "clist", array("id"=>$val['sid'], "pid"=>$pval['pc_id'], "page"=>$i)), $val['fmark'].$sep.$val['mark'].$sep.$pval['pc_id'].$sep."index_$i.html"
												);
											}
										}
									}
								}
							}elseif ($val['iscato']){
								if ($productcatos_rs = $productcatos->findAll(array("markid"=>$val['sid'], "fid" => 0), null, "pc_id")) {
									foreach ($productcatos_rs as $pkey => $pval){
										$htmlurl[] = array(
												array("main", "clist", array("id"=>$val['sid'], "pid"=>$pval['pc_id'])), $val['fmark'].$sep.$val['mark'].$sep.$pval['pc_id'].$sep."index.html"
										);
										$ptotal_rs = $products->find(array("pc_id"=>$pval['pc_id']), null, "count(pid) as total");
										if ($ptotal_rs['total'] > $val['pagesize']) {
											$totalpage = ceil($ptotal_rs['total'] / $val['pagesize']);
											for ($i=1; $i<=$totalpage; $i++){
												$htmlurl[] = array(
														array("main", "clist", array("id"=>$val['sid'], "pid"=>$pval['pc_id'], "page"=>$i)), $val['fmark'].$sep.$val['mark'].$sep.$pval['pc_id'].$sep."index_$i.html"
												);
											}
										}
									}
								}
							}
							/*
							if ($val['subcolumn']) {
								if($p_rs = $products->findAll(array("ptype"=>$val['subcolumn']), null, "pid")){
									foreach ($p_rs as $pkey => $pval){
										$htmlurl[] = array(
											array("main", "clist", array("id"=>$val['sid'], "f"=>$pval['pid'])), $val['fmark']."/".$val['mark']."/f".$pval['pid']."/index.html"
										);
										$ptotal_rs = $products->find(array("subproduct"=>$pval['pid']), null, "count(pid) as total");
										if ($ptotal_rs['total'] > $val['pagesize']) {
											$totalpage = ceil($ptotal_rs['total'] / $val['pagesize']);
											for ($i=1; $i<=$totalpage; $i++){
												$htmlurl[] = array(
													array("main", "clist", array("id"=>$val['sid'], "f"=>$val['subcolumn'], "page"=>$i)), $val['fmark']."/".$val['mark']."/f".$pval['pid']."/index_$i.html"
												);
											}
										}
									}
								}
							}
							if ($val['relatestr']) {
								$relate = explode(",", $val["relatestr"]);
								foreach($relate as $rk => $rv){
									if($p_rs = $products->findAll(array("ptype"=>$rv), null, "pid")){
										foreach ($p_rs as $pkey => $pval){
											$htmlurl[] = array(
												array("main", "clist", array("id"=>$val['sid'], "pid"=>"0", "f"=>"0", "l"=>$pval['pid'])), $val['fmark']."/".$val['mark']."/l".$pval['pid']."/index.html"
											);
											foreach ($p_rs as $kk => $vv){
												$ptotal_rs = $products->find("find_in_set($vv[pid], relatestr)", null, "count(pid) as total");
												if ($ptotal_rs['total'] > $val['pagesize']) {
													$totalpage = ceil($ptotal_rs['total'] / $val['pagesize']);
													for ($i=1; $i<=$totalpage; $i++){
														$htmlurl[] = array(
															array("main", "clist", array("id"=>$val['sid'], "pid"=>"0", "f"=>"0", "l"=>$vv[pid], "page"=>$i)), $val['fmark']."/".$val['mark']."/l".$pval['pid']."/index_$i.html"
														);
													}
												}
											}
											
										}
									}
								}
							}
							*/
						}
					}
				}
				if(!$postdata['type'] || $postdata['type'] == 2){
					//生成详细页
					if ($products_rs = $products->join("hnyn_articlestyle", "hnyn_articlestyle.sid = hnyn_products.ptype")->join("hnyn_articlestyle as b", "b.sid = hnyn_articlestyle.parentid")->findAll(array("hnyn_articlestyle.ishtml"=>1), "hnyn_products.pid asc", "hnyn_products.pid, hnyn_articlestyle.mark, hnyn_articlestyle.islist, b.mark as fmark")) {
						foreach ($products_rs as $key => $val){
							if ($val['islist'] == "1") {
								$htmlurl[] = array(
										array("main", "cdetail", array("id"=>$val['pid'])), $val['fmark'].$sep.$val['mark'].$sep.$val['pid'].".html"
								);
							}else{
								$htmlurl[] = array(
										array("main", "cdetail", array("id"=>$val['pid'])), $val['fmark'].$sep.$val['mark'].".html"
								);
							}
								
						}
					}
				}
			}else{ //更新选择的栏目页
				if(TRUE != $GLOBALS['G_SP']['html']["enabled_zxadv"])
					spClass("spHtml")->clear("main", "clist", array("id"=>$columnid), null, true);
				if ($articlestyle_rs = $articlestyle->find(array("sid"=> $columnid), null, "sid, mark, pagesize, iscato, iscato2, parentid, islist, subcolumn, relatestr")) {
					//选择parent=0的大栏目
					if (intval($articlestyle_rs['parentid']) == 0 && $articlestyle_child_rs = $articlestyle->findAll(array("parentid"=>$articlestyle_rs['sid']), "sid asc", "sid, mark, iscato, iscato2, pagesize, subcolumn, relatestr, islist")) {
						$htmlurl[] = array(
								array("main", "clist", array("id"=>$articlestyle_rs['sid'])), $articlestyle_rs['mark'].$sep."index.html"
						);
						foreach ($articlestyle_child_rs as $key => $val){
							if(!$postdata['type'] || $postdata['type'] == 1){
								if ($val['islist'] == 1) {
									if(TRUE != $GLOBALS['G_SP']['html']["enabled_zxadv"])
										spClass("spHtml")->clear("main", "clist", array("id"=>$val['sid']), null, true);
									$htmlurl[] = array(
										array("main", "clist", array("id"=>$val['sid'])), $articlestyle_rs['mark'].$sep.$val['mark'].$sep."index.html"
									);
									$total_rs = $products->find(array("ptype"=>$val['sid']), null, "count(pid) as total");
									if ($total_rs['total'] > $val['pagesize']) {
										$totalpage = ceil($total_rs['total'] / $val['pagesize']);
										for ($i=1; $i<=$totalpage; $i++){
											$htmlurl[] = array(
													array("main", "clist", array("id"=>$val['sid'], "pid"=>0, "page"=>$i)), $articlestyle_rs['mark'].$sep.$val['mark'].$sep."index_$i.html"
											);
										}
									}
										
									if ($val['iscato2']) {
										if ($productcatos_rs = $productcatos->findAll(array("markid"=>$val['sid'], "fid <>" => 0), null, "pc_id")) {
											foreach ($productcatos_rs as $pkey => $pval){
												$htmlurl[] = array(
														array("main", "clist", array("id"=>$val['sid'], "pid"=>$pval['pc_id'])), $articlestyle_rs['mark'].$sep.$val['mark'].$sep.$pval['pc_id'].$sep."index.html"
												);
												$ptotal_rs = $products->find(array("pc_id"=>$pval['pc_id']), null, "count(pid) as total");
												if ($ptotal_rs['total'] > $val['pagesize']) {
													$totalpage = ceil($ptotal_rs['total'] / $val['pagesize']);
													for ($i=1; $i<=$totalpage; $i++){
														$htmlurl[] = array(
																array("main", "clist", array("id"=>$val['sid'], "pid"=>$pval['pc_id'], "page"=>$i)), $articlestyle_rs['mark'].$sep.$val['mark'].$sep.$pval['pc_id'].$sep."index_$i.html"
														);
													}
												}
											}
										}
									}elseif ($val['iscato']){
										if ($productcatos_rs = $productcatos->findAll(array("markid"=>$val['sid'], "fid" => 0), null, "pc_id")) {
											foreach ($productcatos_rs as $pkey => $pval){
												$htmlurl[] = array(
													array("main", "clist", array("id"=>$val['sid'], "pid"=>$pval['pc_id'])), $articlestyle_rs['mark'].$sep.$val['mark'].$sep.$pval['pc_id'].$sep."index.html"
												);
												$ptotal_rs = $products->find(array("pc_id"=>$pval['pc_id']), null, "count(pid) as total");
												if ($ptotal_rs['total'] > $val['pagesize']) {
													$totalpage = ceil($ptotal_rs['total'] / $val['pagesize']);
													for ($i=1; $i<=$totalpage; $i++){
														$htmlurl[] = array(
															array("main", "clist", array("id"=>$val['sid'], "pid"=>$pval['pc_id'], "page"=>$i)), $articlestyle_rs['mark'].$sep.$val['mark'].$sep.$pval['pc_id'].$sep."index_$i.html"
														);
													}
												}
											}
										}
									}
								}
							}
							/*
							应用面少，耗资较大，冗余较多
							if ($val['subcolumn']) {
								if($p_rs = $products->findAll(array("ptype"=>$val['subcolumn']), null, "pid")){
									foreach ($p_rs as $pkey => $pval){
										$htmlurl[] = array(
											array("main", "clist", array("id"=>$val['sid'], "f"=>$pval['pid'])), $articlestyle_rs['mark']."/".$val['mark']."/f".$pval['pid']."/index.html"
										);
										$ptotal_rs = $products->find(array("subproduct"=>$pval['pid']), null, "count(pid) as total");
										if ($ptotal_rs['total'] > $val['pagesize']) {
											$totalpage = ceil($ptotal_rs['total'] / $val['pagesize']);
											for ($i=1; $i<=$totalpage; $i++){
												$htmlurl[] = array(
													array("main", "clist", array("id"=>$val['sid'], "f"=>$val['subcolumn'], "page"=>$i)), $articlestyle_rs['mark']."/".$val['mark']."/f".$pval['pid']."/index_$i.html"
												);
											}
										}
									}
								}
							}
							if ($val['relatestr']) {
								$relate = explode(",", $val["relatestr"]);
								foreach($relate as $rk => $rv){
									if($p_rs = $products->findAll(array("ptype"=>$rv), null, "pid")){
										foreach ($p_rs as $pkey => $pval){
											$htmlurl[] = array(
												array("main", "clist", array("id"=>$val['sid'], "pid"=>"0", "f"=>"0", "l"=>$pval['pid'])), $articlestyle_rs['mark']."/".$val['mark']."/l".$pval['pid']."/index.html"
											);
											foreach ($p_rs as $kk => $vv){
												$ptotal_rs = $products->find("find_in_set($vv[pid], relatestr)", null, "count(pid) as total");
												if ($ptotal_rs['total'] > $val['pagesize']) {
													$totalpage = ceil($ptotal_rs['total'] / $val['pagesize']);
													for ($i=1; $i<=$totalpage; $i++){
														$htmlurl[] = array(
															array("main", "clist", array("id"=>$val['sid'], "pid"=>"0", "f"=>"0", "l"=>$vv[pid], "page"=>$i)), $articlestyle_rs['mark']."/".$val['mark']."/l".$pval['pid']."/index_$i.html"
														);
													}
												}
											}
											
										}
									}
								}
							}
							*/
							if(!$postdata['type'] || $postdata['type'] == 2){
								if ($products_rs = $products->join("hnyn_articlestyle", "hnyn_articlestyle.sid = hnyn_products.ptype")->findAll(array("hnyn_products.ptype" => $val['sid']), "hnyn_products.pid asc", "hnyn_products.pid, hnyn_articlestyle.mark")) {
									foreach ($products_rs as $pkey => $pval){
										if(TRUE != $GLOBALS['G_SP']['html']["enabled_zxadv"])
											spClass("spHtml")->clear("main", "cdetail", array("id"=>$pval['pid']), null, true);
										if ($val['islist'] == "1") {
											$htmlurl[] = array(
													array("main", "cdetail", array("id"=>$pval['pid'])), $articlestyle_rs['mark'].$sep.$val['mark'].$sep.$pval['pid'].".html"
											);
										}else{
											$htmlurl[] = array(
													array("main", "cdetail", array("id"=>$pval['pid'])), $articlestyle_rs['mark'].$sep.$pval['mark'].".html"
											);
										}
									}
								}
							}
						}
					}else{
						//选择小栏目
						$articlestyle_parent_rs = $articlestyle->find(array("sid"=>$articlestyle_rs['parentid']), "sid asc", "sid, mark, iscato, iscato2, pagesize, islist, subcolumn, relatestr");
						if(!$postdata['type'] || $postdata['type'] == 1){
							if ($articlestyle_rs['islist'] == "1"){
								if(TRUE != $GLOBALS['G_SP']['html']["enabled_zxadv"])
									spClass("spHtml")->clear("main", "clist", array("id"=>$articlestyle_rs['sid']), null, true);
								$htmlurl[] = array(
										array("main", "clist", array("id"=>$articlestyle_rs['sid'])), $articlestyle_parent_rs["mark"].$sep.$articlestyle_rs['mark'].$sep."index.html"
								);
								$total_rs = $products->find(array("ptype"=>$articlestyle_rs['sid']), null, "count(pid) as total");
								if ($total_rs['total'] > $articlestyle_rs['pagesize']) {
									$totalpage = ceil($total_rs['total'] / $articlestyle_rs['pagesize']);
									for ($i=1; $i<=$totalpage; $i++){
										$htmlurl[] = array(
												array("main", "clist", array("id"=>$articlestyle_rs['sid'], "pid"=>0, "page"=>$i)), $articlestyle_parent_rs["mark"].$sep.$articlestyle_rs['mark'].$sep."index_$i.html"
										);
									}
								}
	
								if ($articlestyle_rs['iscato2']) {
									if ($productcatos_rs = $productcatos->findAll(array("markid"=>$articlestyle_rs['sid'], "fid <>" => 0), null, "pc_id")) {
										foreach ($productcatos_rs as $pkey => $pval){
											$htmlurl[] = array(
													array("main", "clist", array("id"=>$articlestyle_rs['sid'], "pid"=>$pval['pc_id'])), $articlestyle_parent_rs["mark"].$sep.$articlestyle_rs['mark'].$sep.$pval['pc_id'].$sep."index.html"
											);
											$ptotal_rs = $products->find(array("pc_id"=>$pval['pc_id']), null, "count(pid) as total");
											if ($ptotal_rs['total'] > $articlestyle_rs['pagesize']) {
												$totalpage = ceil($ptotal_rs['total'] / $articlestyle_rs['pagesize']);
												for ($i=1; $i<=$totalpage; $i++){
													$htmlurl[] = array(
															array("main", "clist", array("id"=>$articlestyle_rs['sid'], "pid"=>$pval['pc_id'], "page"=>$i)), $articlestyle_parent_rs["mark"].$sep.$articlestyle_rs['mark'].$sep.$pval['pc_id'].$sep."index_$i.html"
													);
												}
											}
										}
									}
								}elseif ($articlestyle_rs['iscato']){
									if ($productcatos_rs = $productcatos->findAll(array("markid"=>$articlestyle_rs['sid'], "fid" => 0), null, "pc_id")) {
										foreach ($productcatos_rs as $pkey => $pval){
											$htmlurl[] = array(
													array("main", "clist", array("id"=>$articlestyle_rs['sid'], "pid"=>$pval['pc_id'])), $articlestyle_parent_rs["mark"].$sep.$articlestyle_rs['mark'].$sep.$pval['pc_id'].$sep."index.html"
											);
											$ptotal_rs = $products->find(array("pc_id"=>$pval['pc_id']), null, "count(pid) as total");
											if ($ptotal_rs['total'] > $articlestyle_rs['pagesize']) {
												$totalpage = ceil($ptotal_rs['total'] / $articlestyle_rs['pagesize']);
												for ($i=1; $i<=$totalpage; $i++){
													$htmlurl[] = array(
															array("main", "clist", array("id"=>$articlestyle_rs['sid'], "pid"=>$pval['pc_id'], "page"=>$i)), $articlestyle_parent_rs["mark"].$sep.$articlestyle_rs['mark'].$sep.$pval['pc_id'].$sep."index_$i.html"
													);
												}
											}
										}
									}
								}
								/*
								if ($articlestyle_rs['subcolumn']) {
									if($p_rs = $products->findAll(array("ptype"=>$articlestyle_rs['subcolumn']), null, "pid")){
										foreach ($p_rs as $pkey => $pval){
											$htmlurl[] = array(
												array("main", "clist", array("id"=>$articlestyle_rs['sid'], "f"=>$pval['pid'])), $articlestyle_parent_rs['mark']."/".$articlestyle_rs['mark']."/f".$pval['pid']."/index.html"
											);
											$ptotal_rs = $products->find(array("subproduct"=>$pval['pid']), null, "count(pid) as total");
											if ($ptotal_rs['total'] > $articlestyle_rs['pagesize']) {
												$totalpage = ceil($ptotal_rs['total'] / $articlestyle_rs['pagesize']);
												for ($i=1; $i<=$totalpage; $i++){
													$htmlurl[] = array(
														array("main", "clist", array("id"=>$articlestyle_rs['sid'], "f"=>$pval['pid'], "page"=>$i)), $articlestyle_parent_rs['mark']."/".$articlestyle_rs['mark']."/f".$pval['pid']."/index_$i.html"
													);
												}
											}
										}
									}
								}
								if ($articlestyle_rs['relatestr']) {
									$relate = explode(",", $articlestyle_rs["relatestr"]);
									foreach($relate as $rk => $rv){
										if($p_rs = $products->findAll(array("ptype"=>$rv), null, "pid")){
											foreach ($p_rs as $pkey => $pval){
												$htmlurl[] = array(
													array("main", "clist", array("id"=>$articlestyle_rs['sid'], "pid"=>"0", "f"=>"0", "l"=>$pval['pid'])), $articlestyle_parent_rs['mark']."/".$articlestyle_rs['mark']."/l".$pval['pid']."/index.html"
												);
												$ptotal_rs = $products->find("find_in_set($pval[pid], relatestr)", null, "count(pid) as total");
												if ($ptotal_rs['total'] > $articlestyle_rs['pagesize']) {
													$totalpage = ceil($ptotal_rs['total'] / $articlestyle_rs['pagesize']);
													for ($i=1; $i<=$totalpage; $i++){
														$htmlurl[] = array(
															array("main", "clist", array("id"=>$articlestyle_rs['sid'], "pid"=>"0", "f"=>"0", "l"=>$pval[pid], "page"=>$i)), $articlestyle_parent_rs['mark']."/".$articlestyle_rs['mark']."/l".$pval['pid']."/index_$i.html"
														);
													}
												}
											}
										}
									}
								}
								*/
							}
						}
						if(!$postdata['type'] || $postdata['type'] == 2){
							if ($products_rs = $products->join("hnyn_articlestyle", "hnyn_articlestyle.sid = hnyn_products.ptype")->findAll(array("hnyn_products.ptype" => $columnid), "hnyn_products.pid asc", "hnyn_products.pid, hnyn_articlestyle.mark")) {
								foreach ($products_rs as $pkey => $pval){
									if(TRUE != $GLOBALS['G_SP']['html']["enabled_zxadv"])
										spClass("spHtml")->clear("main", "cdetail", array("id"=>$pval['pid']), null, true);
									if ($articlestyle_rs['islist'] == "1") {
										$htmlurl[] = array(
												array("main", "cdetail", array("id"=>$pval['pid'])), $articlestyle_parent_rs["mark"].$sep.$articlestyle_rs['mark'].$sep.$pval['pid'].".html"
										);
									}else{
										$htmlurl[] = array(
												array("main", "cdetail", array("id"=>$pval['pid'])), $articlestyle_parent_rs["mark"].$sep.$articlestyle_rs['mark'].".html"
										);
									}
								}
							}
						}
					}
				}
			}
			if(TRUE == $GLOBALS['G_SP']['html']["enabled_zxadv"]){
				$this->htmlcontinue_adv($htmlurl);
			}else{
				spClass("spHtml")->zxmakeAll($_SESSION["htmlurl"], 0);
				spClass("spHtml")->zxmakeAll($_SESSION["htmlurl"], 1);
				$message = array('msg'=>'静态页面更新完成！','result'=>1);
				echo json_encode($message);
				exit();
			}
		}
	}
	
	private function htmlcontinue_adv($htmlurl){
		if(!$_SESSION["htmlurl"]){
			$_SESSION["htmlurl"] = $htmlurl;
		}
		$i = 0;
		$page = max(1, intval($this->spArgs("page")));
		$limit = 10;
		$start = ($page - 1) * $limit;
		$end =  $page * $limit;
		$result = "";
		$makepageurl = array();
		foreach($_SESSION["htmlurl"] as $key => $val){
			if($i >= $start && $i < $end){
				$furl = spUrl($val[0][0], $val[0][1], $val[0][2]);
				$makepageurl[] = $val;
				$result .= ($i+1).". <a href='$furl' target='_blank'>$furl</a><br/>";
			}
			$i++;
		}
		//print_r($makepageurl);exit();
		spClass("spHtml")->zxmakeAll($makepageurl, 1);
		$total = count($_SESSION["htmlurl"]);
		$now = $end > $total ? $total : $end;
		$result .= "更新进度 ".$now ."/".$total ."<br/><br/>";
		if($now == $total){
			$result .= "所有页面已更新完成";
			unset($_SESSION["htmlurl"]);
		}else{
			$nexturl = spUrl("main", "htmlupdate", array("page"=>$page+1, "auto"=>1, "cache_adv"=>"zx"));
			$result .= "自动更新中,请稍后。如页面没运行,<a href='".$nexturl."'>点此继续</a>";
			$this->nexturl = $nexturl;
			$this->htmlauto = 1;
		}
		$this->result = $result;
	}
	
	function onehtmlupdate(){
		if (!$_SESSION['admin_user']) return false;
		set_time_limit(900);
		$sep = $GLOBALS['G_SP']['html']['sep'] ? $GLOBALS['G_SP']['html']['sep'] : "/";
		$products = spClass('product');
		$articlestyle = spClass('articlestyle');
		$id = intval($this->spArgs("id"));
		if(TRUE != $GLOBALS['G_SP']['html']["enabled_zxadv"])
			spClass("spHtml")->clear("main", "cdetail", array("id"=>$id), null, true);
		$product_rs = $products->findByPk($id, "ptype");
		$articlestyle_rs = $articlestyle->findByPk($product_rs['ptype'], "sid, islist, parentid, mark");
		$articlestyle_parent_rs = $articlestyle->findByPk($articlestyle_rs['parentid'], "sid, mark");
		$htmlurl[] = array(
			array("main", "cdetail", array("id"=>$id)), ($articlestyle_rs["islist"] ? $articlestyle_parent_rs["mark"].$sep.$articlestyle_rs['mark'].$sep.$id.".html" : $articlestyle_parent_rs["mark"].$sep.$articlestyle_rs['mark'].".html")
		);
		spClass("spHtml")->zxmakeAll($htmlurl, 1);
		$message = array('msg'=>'静态页面更新完成！','result'=>0);
		echo json_encode($message);
		exit();
	}
	
	function sitemapupdate(){
		if (!$_SESSION['admin_user']) return false;
		set_time_limit(900);
		$htmlurl[] = array(
			array("main", "sitemap"), "../sitemap.xml"
		);
		spClass("spHtml")->clear("main", "sitemap", null, null, true);
		spClass("spHtml")->makeAll($htmlurl, 1);
		$message = array('msg'=>'网站地图更新完成！','result'=>1);
		echo json_encode($message);
		exit();
	}
	
	function unhtml(){
		if (!$_SESSION['admin_user']) return false;
		if(TRUE != $GLOBALS['G_SP']['html']["enabled_zxadv"]){
			$message = array('msg'=>'该静态模式不支持此功能！','result'=>0);
			echo json_encode($message);
			exit();
		}
		spClass("spHtml")->clearAll(true);
		$message = array('msg'=>'静态页面销毁成功,现网站已转为动态！','result'=>1);
		echo json_encode($message);
		exit();
	}
}
	
?>